package vivek.project.pocketmoney.investments.model
{
	import flash.data.*;
	import flash.errors.*;
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.core.UIComponent;
	
	import vivek.project.pocketmoney.admin.model.AdminConstants;
	import vivek.project.pocketmoney.admin.model.AdminDataCache;
	import vivek.project.pocketmoney.admin.model.AdminDataModel;
	import vivek.project.pocketmoney.common.CommonData;
	import vivek.project.pocketmoney.common.PocketmoneyDataInterface;
	import vivek.project.pocketmoney.common.interfaces.*;
	import vivek.project.pocketmoney.common.logger.InvestmentLogger;
	import vivek.project.pocketmoney.common.utils.ArrayUtils;
	import vivek.project.pocketmoney.common.utils.CommonConstants;
	import vivek.project.pocketmoney.common.utils.DateUtils;
	import vivek.project.pocketmoney.expenses.model.ExpenseDataModel;
	import vivek.project.pocketmoney.investments.scripts.InvestmentSQLScript;

	public class FixedIncomeDataModel extends UIComponent implements PocketmoneyDataInterface
	{
		private static var MODULE:String="INVESTMENTS";
		private static var instance:FixedIncomeDataModel;

		public static function getInstance():FixedIncomeDataModel
		{
			if (!instance)
			{
				instance=new FixedIncomeDataModel();
			}
			return instance;
		}

		public function FixedIncomeDataModel():void
		{
			addEventListener("InvestmentAdded", refreshInvestment);
			addEventListener("InvestmentDeleted", refreshInvestment);
			addEventListener("InvestmentUpdated", refreshInvestment);
			addEventListener("FixedIncomeRecurussionAdded", refreshInvestment);
			AdminDataModel.getInstance().addEventListener("USERCHANGED", loadDataOnEvent);
			loadData();
		}
		private var edm:ExpenseDataModel=ExpenseDataModel.getInstance();

		public function addBullionTransaction(bullionObj:Object):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var randomId:Number=new Number();
				randomId=Math.round(Math.random() * 1000000000);
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.ADD_NEW_BULLIONTRANSACTION;
				_statement.parameters[":bm_id"]=randomId;
				_statement.parameters[":bm_type"]=bullionObj.investmenttypeid;
				_statement.parameters[":bm_accountid"]=bullionObj.account;
				_statement.parameters[":bm_channelid"]=bullionObj.channel;
				_statement.parameters[":bm_transactiontype"]=bullionObj.transactiontype;
				_statement.parameters[":bm_transactiondate"]=bullionObj.txndate;
				_statement.parameters[":bm_quantity"]=bullionObj.qty;
				_statement.parameters[":bm_costper10g"]=bullionObj.price;
				_statement.parameters[":bm_othercharges"]=bullionObj.brokerage;
				_statement.parameters[":bm_remarks"]=bullionObj.remarks;
				_statement.parameters[":USERID"]=AdminDataCache.ACCOUNT_IN_USE;
				_statement.execute();
				var expRecord:Object=new Object();
				if (bullionObj.type == InvestmentConstants.BUY)
				{
					expRecord.account=bullionObj.account;
					expRecord.transferAccount=bullionObj.channel;
					expRecord.amount=((new Number(bullionObj.price) / 10) * new Number(bullionObj.qty) / 10) + new Number(bullionObj.brokerage);
				}
				else
				{
					expRecord.account=bullionObj.channel;
					expRecord.transferAccount=bullionObj.account;
					expRecord.amount=((new Number(bullionObj.price) / 10) * new Number(bullionObj.qty)) - new Number(bullionObj.brokerage);
				}
				expRecord.category=CommonConstants.INVESTMENT_CATEGORY_ID;
				expRecord.payee=0;
				expRecord.memo="Bullion Investment";
				expRecord.date=bullionObj.txndate;
				expRecord.exRate=1.0;
				edm.addDependentTransferRecord(expRecord, randomId, _sqlConnection, true);
				_sqlConnection.commit();
				_sqlConnection.close();
				InvestmentLogger.logRecord(MODULE, "Bullion Added", expRecord);
				dispatchEvent(new Event("InvestmentAdded"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
					//Alert.show(sqlError.details);
			}
			return 1;
		}

		public function addInvestmentRecursionTransaction(bullionObj:Object):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.ADD_NEW_INVESTMENTRECURSSION;
				_statement.parameters[":fr_investid"]=bullionObj.fm_investmentid;
				_statement.parameters[":fr_type"]=bullionObj.fm_type;
				_statement.parameters[":fr_account"]=bullionObj.fm_accountid;
				_statement.parameters[":fr_startdate"]=bullionObj.fm_investDateRecur;
				_statement.parameters[":fr_percent"]=bullionObj.fm_percent;
				//_statement.parameters[":fr_investperiod"]=bullionObj.fm_investperiod;
				//_statement.parameters[":fr_comments"]=bullionObj.fm_comments;
				_statement.parameters[":fr_amount"]=bullionObj.fm_investmentamount;
				_statement.parameters[":fr_name"]=bullionObj.fm_investmentname;
				_statement.parameters[":fr_status"]=bullionObj.fm_status;
				_statement.parameters[":fr_date"]=bullionObj.fm_ondate;
				var endDate:Date=bullionObj.fm_investDateRecur;
				endDate=DateUtils.dateAdd("date", bullionObj.fm_investperiod, bullionObj.fm_investDateRecur);
				_statement.parameters[":fr_enddate"]=endDate;
				_statement.parameters[":fr_nextexecution"]=RecurssionInterface.getNextExecutionDate(bullionObj.fm_investDate, endDate, bullionObj.fm_ondate);
				_statement.parameters[":fr_investperiod"]=bullionObj.fm_investperiod;
				_statement.parameters[":USERID"]=AdminDataCache.ACCOUNT_IN_USE;
				_statement.execute();
				_sqlConnection.commit();
				_sqlConnection.close();
				InvestmentLogger.logRecord(MODULE, "Investment Added", bullionObj);
				//edm.refreshExpenseDataCache(null);
				dispatchEvent(new Event("FixedIncomeRecurussionAdded"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
					//Alert.show(sqlError.details);
			}
			return 1;
		}

		public function addInvestmentTransaction(bullionObj:Object):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var randomId:Number=new Number();
				randomId=Math.round(Math.random() * 1000000000);
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.ADD_NEW_INVESTMENTTRANSACTION;
				_statement.parameters[":fm_investmentid"]=randomId;
				_statement.parameters[":fm_type"]=bullionObj.fm_type;
				_statement.parameters[":fm_accountid"]=bullionObj.fm_accountid;
				_statement.parameters[":fm_channelid"]=0; //bullionObj.fm_channelid;	
				_statement.parameters[":fm_investmentdate"]=bullionObj.fm_investmentdate;
				_statement.parameters[":fm_percent"]=bullionObj.fm_percent;
				_statement.parameters[":fm_maturityamount"]=bullionObj.fm_maturityamount;
				_statement.parameters[":fm_investperiod"]=bullionObj.fm_investperiod;
				_statement.parameters[":fm_comments"]=bullionObj.fm_comments;
				_statement.parameters[":fm_investmentamount"]=bullionObj.fm_investmentamount;
				_statement.parameters[":fm_investmentname"]=bullionObj.fm_investmentname;
				_statement.parameters[":fm_status"]=bullionObj.fm_status;
				_statement.parameters[":fm_maturitydate"]=bullionObj.fm_maturitydate;
				_statement.parameters[":fm_recurring"]=bullionObj.fm_recurring; //_statement.parameters[":fm_txntype"]=bullionObj.txnType;
				_statement.parameters[":USERID"]=AdminDataCache.ACCOUNT_IN_USE;
				_statement.execute();
				var expRecord:Object=new Object();
				if (bullionObj.type == InvestmentConstants.BUY)
				{
					expRecord.type=AdminConstants.WITHDRAWAL;
					expRecord.account=bullionObj.fm_accountid;
				//	expRecord.transferAccount=CommonConstants.INVESTMENT_ACCOUNTID;
					expRecord.amount=bullionObj.fm_investmentamount;
				}
				else
				{
					expRecord.type=AdminConstants.DEPOSIT;
					expRecord.account=bullionObj.fm_accountid;
					//expRecord.transferAccount=bullionObj.fm_accountid;
					//expRecord.account=CommonConstants.INVESTMENT_ACCOUNTID;
					expRecord.amount=bullionObj.fm_maturityamount;
				}
				expRecord.category=CommonConstants.INVESTMENT_CATEGORY_ID;
				expRecord.payee=0;
				expRecord.memo="Fixed Income";
				expRecord.date=bullionObj.fm_investmentdate;
				expRecord.exRate=1.0;
				expRecord.userid=AdminDataCache.ACCOUNT_IN_USE;
				if (expRecord.fm_accountid != 0)
					edm.addDependentExpenseRecord(expRecord, randomId, _sqlConnection);
				_sqlConnection.commit();
				_sqlConnection.close();
				InvestmentLogger.logRecord(MODULE, "Investment Added", bullionObj);
				//edm.refreshExpenseDataCache(null);
				dispatchEvent(new Event("InvestmentAdded"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
					//Alert.show(sqlError.details);
			}
			return randomId;
		}

		public function clearSellTransaction(bullionObj:Object):void
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var randomId:Number=new Number();
				randomId=Math.round(Math.random() * 1000000000);
				var selltxnid:int=0;
				if (bullionObj.fm_selltxnid == 0)
					selltxnid=randomId;
				else
					selltxnid=bullionObj.fm_selltxnid;
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.CLEAR_SELL_FIXED_INCOME_TRANSACTION;
				_statement.parameters[":fm_investmentid"]=bullionObj.fm_investmentid;
				_statement.execute();
				edm.deleteDependentExpense(selltxnid, false, _sqlConnection);
				_sqlConnection.commit();
				_sqlConnection.close();
				//edm.refreshExpenseDataCache(null);
				dispatchEvent(new Event("InvestmentAdded"));
			}
			catch (e:Error)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
			}
		}

		public function deleteInvestments(bullionObj:Array):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.DELETE_INVESTMENT;
				for each (var obj:Object in bullionObj)
				{
					_statement.parameters[":fm_investmentid"]=obj.fm_investmentid;
					_statement.execute();
					edm.deleteDependentExpense(obj.fm_investmentid, false, _sqlConnection);
					obj.message="INVESTMENT DELETED";
					InvestmentLogger.logMultiple(obj);
				}
				_sqlConnection.commit();
				_sqlConnection.close();
				InvestmentLogger.flush();
				dispatchEvent(new Event("InvestmentDeleted"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
					//Alert.show(sqlError.details);
			}
			return 1;
		}

		public function deleteInvestmentsId(bullionObj:Array):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.DELETE_INVESTMENT;
				for each (var obj:int in bullionObj)
				{
					_statement.parameters[":fm_investmentid"]=obj;
					_statement.execute();
					edm.deleteDependentExpense(obj, false, _sqlConnection);
					//obj.message="INVESTMENT DELETED";
					InvestmentLogger.logMultiple(bullionObj);
				}
				_sqlConnection.commit();
				_sqlConnection.close();
				InvestmentLogger.flush();
				dispatchEvent(new Event("InvestmentDeleted"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
					//Alert.show(sqlError.details);
			}
			return 1;
		}

		public function getInvestmentTypeDetails(id:int):Object
		{
			for each (var o:Object in AdminDataCache.accountType)
			{
				if (o.at_id == id)
					return o;
			}
			return null;
		}

		public function getInvestmentTypeName(investmentTypeId:int):String
		{
			for each (var o:Object in InvestmentDataCache.investmentTypeData)
			{
				if (o.it_investmenttypeid == investmentTypeId)
					return o.it_investmenttypename;
			}
			return "";
		}

		public function getTotalExpectedMaturityAmount():int
		{
			var amount:int=0;
			for each (var o:Object in InvestmentDataCache.fixedIncomeData)
			{
				amount+=o.fm_maturityamount;
			}
			return amount;
		}

		public function getTotalInvestmentAmount():int
		{
			var amount:int=0;
			for each (var o:Object in InvestmentDataCache.fixedIncomeData)
			{
				amount+=o.fm_investmentamount;
			}
			return amount;
		}

		private function calculateSummary():void
		{
			var matchingItems:Array=new Array();
			var groupArray:Array=new Array();
			for each (var o:Object in InvestmentDataCache.fixedIncomeData)
			{
				matchingItems=ArrayUtils.findMatchingItem(o, groupArray, ['fm_type'])
				if (matchingItems.length == 0)
				{
					var j:Object=new Object();
					j.fm_type=o.fm_type;
					j.fm_investmentamount=o.fm_investmentamount - o.fm_sellamount;
					groupArray.push(j);
				}
				else
				{

					var j1:Object=new Object();
					j1=matchingItems[0];

					j1.fm_investmentamount=j1.fm_investmentamount + o.fm_investmentamount - o.fm_sellamount;
				}
			}

			InvestmentDataCache.fixedIncomeSummary.source=groupArray;
		}

		public function loadData():void
		{
			var _statement:SQLStatement=new SQLStatement();
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			_statement.sqlConnection=_sqlConnection;
			_statement.text=InvestmentSQLScript.INVESTMENTTYPE_GET_DATA_ALL;
			_statement.execute();
			InvestmentDataCache.investmentTypeData=new ArrayCollection(_statement.getResult().data);
			_statement.text=InvestmentSQLScript.FIXEDINCOME_GET_DATA_ALL;
			_statement.parameters[":USERID"]=AdminDataCache.ACCOUNT_IN_USE;
			_statement.execute();
			InvestmentDataCache.fixedIncomeData=new ArrayCollection(_statement.getResult().data);
			_statement.text=InvestmentSQLScript.BULLION_GET_DATA_ALL;
			_statement.parameters[":USERID"]=AdminDataCache.ACCOUNT_IN_USE;
			_statement.execute();
			InvestmentDataCache.bullionData=new ArrayCollection(_statement.getResult().data);
			_statement.text=InvestmentSQLScript.GET_DATA_FIXEDINCOME_RECURUSSION;
			_statement.parameters[":USERID"]=AdminDataCache.ACCOUNT_IN_USE;
			_statement.execute();
			InvestmentDataCache.fixedIncomeRecurssionData=new ArrayCollection(_statement.getResult().data);
			_sqlConnection.close();
			calculateSummary();
		}

		public function sellInvestmentTransaction(bullionObj:Object):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			//_sqlConnection.open();
			try
			{
				var randomId:Number=new Number();
				randomId=Math.round(Math.random() * 1000000000);
				var selltxnid:int=0;
				if (bullionObj.fm_selltxnid == 0)
					selltxnid=randomId;
				else
					selltxnid=bullionObj.fm_selltxnid;
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.SELL_INVESTMENT_TRANSACTION;
				_statement.parameters[":fm_investmentid"]=bullionObj.fm_investmentid;
				_statement.parameters[":fm_sellamount"]=bullionObj.fm_sellamount;
				_statement.parameters[":fm_selldate"]=bullionObj.fm_sellDate;
				_statement.parameters[":fm_sellaccount"]=bullionObj.fm_sellaccount;
				_statement.parameters[":fm_selltxnid"]=selltxnid;
				_statement.execute();
				var expRecord:Object=new Object();
				expRecord.type=CommonConstants.SELL;
				expRecord.transferAccount=bullionObj.fm_sellaccount;
				expRecord.account=bullionObj.fm_channelid;
				expRecord.amount=bullionObj.fm_sellamount;
				expRecord.category=CommonConstants.INVESTMENT_CATEGORY_ID;
				expRecord.payee=0;
				expRecord.memo="Fixed Income - SOLD";
				expRecord.date=bullionObj.fm_sellDate;
				expRecord.exRate=1.0;
				edm.updateDependentTransferRecord(expRecord, selltxnid, _sqlConnection);
				_sqlConnection.commit();
				_sqlConnection.close();
				//edm.refreshExpenseDataCache(null);
				dispatchEvent(new Event("InvestmentAdded"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
					//Alert.show(sqlError.details);
			}
			return 1;
		}

		public function updateBullionTransaction(bullionObj:Object):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			try
			{
				//_sqlConnection.open();
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.UPDATE_BULLIONTRANSACTION;
				_statement.parameters[":bm_type"]=bullionObj.investmenttypeid;
				_statement.parameters[":bm_accountid"]=bullionObj.account;
				_statement.parameters[":bm_channelid"]=bullionObj.channel;
				_statement.parameters[":bm_transactiontype"]=bullionObj.transactiontype;
				_statement.parameters[":bm_quantity"]=bullionObj.qty;
				_statement.parameters[":bm_transactiondate"]=bullionObj.txndate;
				_statement.parameters[":bm_costper10g"]=bullionObj.price;
				_statement.parameters[":bm_othercharges"]=bullionObj.brokerage;
				_statement.parameters[":bm_remarks"]=bullionObj.remarks;
				_statement.parameters[":bm_id"]=bullionObj.bm_id;
				_statement.execute();
				var expRecord:Object=new Object();
				if (bullionObj.type == InvestmentConstants.BUY)
				{
					expRecord.account=bullionObj.account;
					expRecord.transferAccount=bullionObj.channel;
					expRecord.amount=((new Number(bullionObj.price) / 10) * new Number(bullionObj.qty) / 10) + new Number(bullionObj.brokerage);
				}
				else
				{
					expRecord.account=bullionObj.channel;
					expRecord.transferAccount=bullionObj.account;
					expRecord.amount=((new Number(bullionObj.price) / 10) * new Number(bullionObj.qty)) - new Number(bullionObj.brokerage);
				}
				expRecord.category=CommonConstants.INVESTMENT_CATEGORY_ID;
				expRecord.payee=0;
				expRecord.memo="Bullion Investment";
				expRecord.date=bullionObj.txndate;
				expRecord.exRate=1.0;
				edm.updateDependentTransferRecord(expRecord, bullionObj.bm_id, _sqlConnection);
				_sqlConnection.commit();
				_sqlConnection.close();
				dispatchEvent(new Event("BullionUpdated"));
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
				trace(sqlError.details);
			}
			return 1;
		}

		public function updateFixedIncomeNextExecutionDate(obj:Object, connection:SQLConnection, date:Date, refresh:Boolean):void
		{
			trace(new Date().toLocaleTimeString() + "FIR: start add 1");
			var _statement:SQLStatement=new SQLStatement();
			_statement.sqlConnection=connection;
			_statement.text="update fixedincomerecurssion set fr_nextexecution = :nextExecutionDate, fr_lastexecution=:lastExecutedDate where fr_id = :fr_id";
			_statement.parameters[":nextExecutionDate"]=obj.nextExecutionDate;
			_statement.parameters[":lastExecutedDate"]=obj.lastExecutedDate;
			_statement.parameters[":fr_id"]=obj.fm_id;
			_statement.execute();
			refreshInvestment(null);
		}

		public function updateFixedIncomeTransaction(fixedIncomeObj:Object):int
		{
			var _sqlConnection:SQLConnection=CommonData.getConnection();
			try
			{
				//_sqlConnection.open();
				var _statement:SQLStatement=new SQLStatement();
				_statement.sqlConnection=_sqlConnection;
				_sqlConnection.begin();
				_statement.text=InvestmentSQLScript.UPDATE_FIXED_INCOME_TRANSACTION;
				_statement.parameters[":fm_investmentid"]=fixedIncomeObj.fm_investmentid;
				_statement.parameters[":fm_type"]=fixedIncomeObj.fm_type;
				_statement.parameters[":fm_accountid"]=fixedIncomeObj.fm_accountid;
				_statement.parameters[":fm_channelid"]=fixedIncomeObj.fm_channelid;
				_statement.parameters[":fm_investmentdate"]=fixedIncomeObj.fm_investmentdate;
				_statement.parameters[":fm_percent"]=fixedIncomeObj.fm_percent;
				_statement.parameters[":fm_maturityamount"]=fixedIncomeObj.fm_maturityamount;
				_statement.parameters[":fm_investperiod"]=fixedIncomeObj.fm_investperiod;
				_statement.parameters[":fm_comments"]=fixedIncomeObj.fm_comments;
				_statement.parameters[":fm_investmentamount"]=fixedIncomeObj.fm_investmentamount;
				_statement.parameters[":fm_investmentname"]=fixedIncomeObj.fm_investmentname;
				_statement.parameters[":fm_status"]=fixedIncomeObj.fm_status;
				_statement.parameters[":fm_maturitydate"]=fixedIncomeObj.fm_maturitydate;
				//	_statement.parameters[":fm_txntype"]=fixedIncomeObj.txnType;
				_statement.execute();
				var expRecord:Object=new Object();
				if (fixedIncomeObj.type == InvestmentConstants.BUY)
				{
					expRecord.type=CommonConstants.BUY;
					expRecord.account=fixedIncomeObj.fm_accountid;
					expRecord.transferAccount=fixedIncomeObj.fm_channelid;
				}
				else
				{
					expRecord.type=CommonConstants.SELL;
					expRecord.transferAccount=fixedIncomeObj.fm_accountid;
					expRecord.account=fixedIncomeObj.fm_channelid;
				}
				expRecord.amount=fixedIncomeObj.fm_investmentamount;
				expRecord.category=CommonConstants.INVESTMENT_CATEGORY_ID;
				expRecord.payee=0;
				expRecord.memo="FIXED INCOME INVESTMENT";
				expRecord.date=fixedIncomeObj.fm_investmentdate;
				expRecord.exRate=1.0;
				edm.updateDependentTransferRecord(expRecord, fixedIncomeObj.fm_investmentid, _sqlConnection);
				_sqlConnection.commit();
				_sqlConnection.close();
				dispatchEvent(new Event("InvestmentUpdated"));
				InvestmentLogger.logRecord("EXPENSE", "EXPENSE UPDATED", fixedIncomeObj);
			}
			catch (sqlError:SQLError)
			{
				_sqlConnection.rollback();
				_sqlConnection.close();
				trace(sqlError.details);
			}
			return 1;
		}

		private function loadDataOnEvent(e:Event):void
		{
			loadData();
			//dispatchEvent(new Event("InvestmentChanged"));
		}

		private function refreshInvestment(e:Event):void
		{
			loadData();
			edm.refreshExpenseDataCache(null);
			//dispatchEvent(new Event("InvestmentChanged"));
		}
	}
}